
class Animal{
    public String name;
    public int age;

    public Animal(String name,int age){
        this.name = name;
        this.age = age;
    }

    public void eat(){
        System.out.println(name + "正在吃东西...");
    }
}

class Dog extends Animal{

    public Dog(String name,int age){
        super(name,age);
    }

    public void bark(){
        System.out.println(name + "正在汪汪叫...");
    }

    public void eat(){
        System.out.println(name + "正在吃狗粮...");
    }
}

class Bird extends Animal{

    public Bird(String name,int age){
        super(name, age);
    }

    public void fly(){
        System.out.println(name + "正在飞...");
    }

    public void eat(){
        System.out.println(name + "正在吃鸟粮...");
    }
}

public class Test {

    public static void main(String[] args) {
//        向上转型：
        Animal animal1 = new Dog("旺财",3);
        if(animal1 instanceof Dog){
            Dog dog = (Dog)animal1;
            dog.bark();
        }
        System.out.println("==================");
        if(animal1 instanceof Bird){
            Bird bird = (Bird) animal1;
            bird.fly();
        }else{
            System.out.println("animal1没有引用Bird的实例");
        }


    }






//    向上转型：

    public static void test1(Animal animal){
        animal.eat();
    }

    public static Animal test2(){
        return new Dog("旺财",2);
    }

    public static void main1(String[] args) {
        Animal animal1 = new Dog("旺财",2);
        test1(animal1);

        Animal animal2 = new Bird("鹏鹏",3);
        test1(animal2);




//        test1(animal);
//        test1(new Dog("旺财",2));

    }
}
